package com.lingying.caiwudailikehudaun.controller.renYuanXInXi;

import com.alibaba.fastjson.JSONObject;
import com.lingying.caiwudailikehudaun.domain.renYuanXinXi.RenYuanXinXiBean;
import com.lingying.caiwudailikehudaun.mapper.renYuanXinXi.RenYuanXinXiMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/renYuanXinXi")
public class RenYuanXinXiController {
    @Resource
    HttpServletRequest httpServletRequest;
    @Resource
    RenYuanXinXiMapper renYuanXinXiMapper;

    /**
     * 人员信息表数据展示接口
     * 桑满  20210428
     * @return
     */
    @GetMapping("/queryUserBean")
    public Object queryUserBean(@RequestParam(value = "yuanGongName", required = false) String yuanGongName,
                                @RequestParam(value = "zhengJianHao", required = false) String zhengJianHao,
                                @RequestParam(value = "yuanGongPhone", required = false) String yuanGongPhone,
                                @RequestParam(value = "yuanGongBuMen", required = false) Integer yuanGongBuMen,
                                @RequestParam(value = "renYuanZhuangTai", required = false) Integer renYuanZhuangTai,
                                @RequestParam(value = "yuanGongBeginMoney", required = false) Integer yuanGongBeginMoney,
                                @RequestParam(value = "yuanGongEndMoney", required = false) Integer yuanGongEndMoney,
                                @RequestParam(value = "congYeBeginTime", required = false) String congYeBeginTime,
                                @RequestParam(value = "congYeEndTime", required = false) String congYeEndTime,
                                @RequestParam(value = "liZhiBeginTime", required = false) String liZhiBeginTime,
                                @RequestParam(value = "liZhiEndTime", required = false) String liZhiEndTime,
                                @RequestParam(value = "shiFouZuoZhang", required = false) Integer shiFouZuoZhang,
                                @RequestParam(value = "shiFouShenBao", required = false) Integer shiFouShenBao,
                                @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                                @RequestParam(value = "limit", defaultValue = "10", required = false) Integer limit
                                ){
        JSONObject object=new JSONObject();
        Integer pages=(page-1)*limit;

        //从session中拿到当前登录用户的jigouid
        Integer zuoZhangShenBaoId = (Integer) httpServletRequest.getSession().getAttribute("zuoZhangShenBaoId");
//        System.err.println("====>"+zuoZhangShenBaoId);
//        Integer jiGouId=1;
//        System.err.println("jiGouId======>"+jiGouId);
        //通过条件查询当前机构下的所有员工信息
        List<RenYuanXinXiBean> renYuanXinXiList=renYuanXinXiMapper.queryUserBean(yuanGongName, zhengJianHao, yuanGongPhone, yuanGongBuMen, renYuanZhuangTai,
                yuanGongBeginMoney, yuanGongEndMoney, congYeBeginTime, congYeEndTime, liZhiBeginTime, liZhiEndTime, shiFouZuoZhang, shiFouShenBao, zuoZhangShenBaoId, pages, limit);
//        System.out.println(renYuanXinXiList);
        //查询到数据总条数
        Integer count=renYuanXinXiMapper.queryUserBeanCount(yuanGongName, zhengJianHao, yuanGongPhone, yuanGongBuMen, renYuanZhuangTai,
                yuanGongBeginMoney, yuanGongEndMoney, congYeBeginTime, congYeEndTime, liZhiBeginTime, liZhiEndTime, shiFouZuoZhang, shiFouShenBao, zuoZhangShenBaoId);
        //将查询结果装进object中并返回前端
        if(renYuanXinXiList!=null){
            object.put("code",0);
            object.put("mag","查询成功");
            object.put("count",count);
            object.put("data",renYuanXinXiList);
        }else{
            object.put("code",500);
            object.put("mag","查询失败");
        }
        return object;
    }

    /**
     * 查询员工信息，返回前端页面下拉回显
     * 桑满  20210428
     * @return
     */
    @GetMapping("/quweyYuanGongXinXi")
    public Object quweyYuanGongXinXi(){
        JSONObject object=new JSONObject();
        Integer zuoZhangShenBaoId = (Integer) httpServletRequest.getSession().getAttribute("zuoZhangShenBaoId");
//        System.err.println("zuoZhangShenBaoId==========>"+zuoZhangShenBaoId);
        List<RenYuanXinXiBean> renYuanXinXiList=renYuanXinXiMapper.queryYuanGongXinXi(zuoZhangShenBaoId);
        if(renYuanXinXiList!=null){
            object.put("code",0);
            object.put("mag","查询成功");
            object.put("data",renYuanXinXiList);
        }else{
            object.put("code",500);
            object.put("mag","查询失败");
        }
        return object;
    }

}













